package com.qingke.pms.util;

import java.util.Scanner;

public class PMSConsole {
	private static Scanner sc=new Scanner(System.in);
	
	private PMSConsole(){
		
	}
	
	public static void print(String str){
		System.out.print(str);
	}
	
	public static void print(Object obj){
		System.out.print(obj);
	}
	
	public static void println(){
		System.out.println();
	}
	
	public static void println(String str){
		System.out.println(str);
	}
	
	public static void println(Object obj){
		System.out.println(obj);
	}
	
	public static String promptNotEmpty(String str){
		String input;
		while(true){
			System.out.print(str);
			input=sc.nextLine();
			if(input.trim().equals(""))
				System.out.println("输入不能为空.");
			else
				break;
				
		}
		return input;
	}
	
	public static String prompt(String str){
		String input;
		while(true){
			System.out.print(str);
			input=sc.nextLine();
			if(input.trim().equals(""))
				continue;
			break;
		}
		return input;
	}
	
	public static String promptCanEmpty(String str){
		String input;
		System.out.print(str);
		input=sc.nextLine();
		return input;
	}
	
	public static int getInt(String cmd){
		String numStr;
		while(true){
			numStr=promptNotEmpty(cmd);
			if(!numStr.matches("[0-9]+")){
				println("err input");
				continue;
			}
			break;
		}
		return Integer.parseInt(numStr);
	}
	
	public static double getDouble(String cmd){
		String numStr;
		while(true){
			numStr=promptNotEmpty(cmd);
			if(!numStr.matches("^[0-9]+(\\.[0-9]+)?$")){
				println("err input");
				continue;
			}
			break;
		}
		return Double.parseDouble(numStr);
	}
	
	public static void close(){
		sc.close();
	}
	
}
